module.exports = function (succ, err) {
    //判断是否需要错误函数
    if (typeof err != "function") {
        err = () => {
            console.log("连接失败!");
        }
    }
    //引入mongoose模块
    const mongoose = require("mongoose")
    //引入config配置
    const { DBHOST, DBPORT, DBNAME, USERNAME, PASSWORD } = require("../config/config.js")

    //连接mongoose数据库
    let address = `mongodb://${USERNAME}:${PASSWORD}@${DBHOST}:${DBPORT}/${DBNAME}`

    mongoose.connect(address)
    //创建响应函数
    mongoose.connection.on("open", () => {
        succ()
    })
    mongoose.connection.on("close", () => {
        console.log("连接关闭!");
    })
    mongoose.connection.on("err", () => {
        err()
    })
}